from numpy import *

class GenericDataset:
    training_data = None
    training_labels = None


    def fetch_pattern(self):
        try:
            return (self.training_data.pop(0),self.training_labels.pop(0))
        except:
            return None

    def fetch_all(self):
        return (self.training_data,self.training_labels)

    def load_training_file(self, url, dimensions, separator=','):
        f = open(url)
        training_data = []
        training_labels = []
        for line in f:
            line = line.split(separator)
            reduce = lambda x : (float(x))/200000.0
            line = map(reduce,line)
            #print line
            training_data.append(line[:dimensions[0]])
            training_labels.append(line[dimensions[0]:])
        f.close()
        self.training_data = training_data
        self.training_labels = training_labels

    def __str__(self):
        out = '* generic dataset \n'
        out += str(len(self.training_data))
        return out